package com.ytjj.qmyx.admin.controller;

import com.ytjj.common.api.CommonResult;
import com.ytjj.common.service.RedisService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author jiawei
 * @date 2023年03月01日 17:15
 * @describe 获取redis数据
 */
@RequestMapping("/redisInfoController")
@RestController
public class RedisInfoController {
    @Autowired
    RedisService redisService;

    /**
     * 获得redis的值
     * @return
     */
    @GetMapping(value = "/getRedisString")
    public CommonResult<String> getRedisString(String key) {
        String data = redisService.get(key);
        return CommonResult.success(data);
    }

    /**
     * 获得redis的值
     * @return
     */
    @GetMapping(value = "/updateRedisString")
    CommonResult updateRedisString(@RequestParam("key") String key,@RequestParam("value")String value,@RequestParam("expire")long expire) {
        redisService.set(key,value,expire);
        return CommonResult.success();
    }

    /**
     * 删除redis的值
     */
    @GetMapping(value = "/deleteProductRedis")
    void deleteProductRedis(@RequestParam String key){
        redisService.delete(key);
    }
}
